package cn.icebreak.cartoon.ui.read;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import cn.icebreak.cartoon.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class ItemsFragment extends Fragment {


    @BindView(R.id.rcv_items)
    RecyclerView rcvItems;
    Unbinder unbinder;
    CatalogueAdapter adapter;
    View rootView;

    public ItemsFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        rootView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_items, null, false);
        unbinder = ButterKnife.bind(this, rootView);

        List<CatalogueBean> list = new ArrayList<CatalogueBean>();
        list.add(new CatalogueBean("", "第1话", "2018-07-01"));
        list.add(new CatalogueBean("", "第2话", "2018-07-02"));
        list.add(new CatalogueBean("", "第3话", "2018-07-03"));
        list.add(new CatalogueBean("", "第4话", "2018-07-03"));
        list.add(new CatalogueBean("", "第5话", "2018-07-03"));
        list.add(new CatalogueBean("", "第6话", "2018-07-03"));
        list.add(new CatalogueBean("", "第7话", "2018-07-03"));
        list.add(new CatalogueBean("", "第8话", "2018-07-03"));
        list.add(new CatalogueBean("", "第9话", "2018-07-03"));
        list.add(new CatalogueBean("", "第10话", "2018-07-03"));


        adapter = new CatalogueAdapter(getActivity(), list);

        rcvItems.setItemAnimator(new DefaultItemAnimator());
        rcvItems.setLayoutManager(new LinearLayoutManager(getActivity()));//这里用线性显示 类似于listview
        //添加分割线
//        recyclerView.addItemDecoration(new RecyclerViewDivider(this,
//                LinearLayoutManager.VERTICAL,
//                DensityUtils.dp2px(this, 10),
//                ContextCompat.getColor(this, R.color.transparent)));

        rcvItems.setAdapter(adapter);
        rcvItems.setNestedScrollingEnabled(false);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }
}
